package cc.recent.normal.information;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;

import java.util.Map;
import java.util.UUID;

import cc.recent.normal.information.multi_engine.SerializableMap;
import cc.recent.normal.information.multi_engine.SnakeActivity;
import cc.recent.normal.information.multi_engine.SnakeFragmentActivity;


public class NativePageActivity extends Activity {

    private static final String TAG = "";

    private TextView mTitleView;

    @Override
    protected void onNewIntent(Intent intent) {
        System.out.println("任务信息：   onNewIntent" + getTaskId());
        super.onNewIntent(intent);
        Log.d(TAG, "onNewIntent: ");
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_native_page);
        mTitleView = findViewById(R.id.tv_title);

        Intent intent = getIntent();
        if (intent != null){
            SerializableMap wrapperMap = (SerializableMap) intent.getSerializableExtra("args");
            Map<String, Object> args = wrapperMap.getMap();
            if (args.containsKey("type")){
                String type = (String) args.get("type");
                mTitleView.setText(type);
            }
        }

        findViewById(R.id.button_back).setOnClickListener(v -> {
            finish();
        });
        Button button1 = findViewById(R.id.button_open_flutter_page);
        button1.setVisibility(View.GONE);
        Button button2 = findViewById(R.id.button_open_flutter_fragment_page);
        if (mTitleView.getText().toString().equals("客户详情")){
            button2.setText("新增睇楼纸");
        }else if (mTitleView.getText().toString().equals("楼盘详情")){
            button2.setVisibility(View.GONE);
        }
        Button button3 = findViewById(R.id.button_back_flutter);
        button1.setOnClickListener(v -> {

            SnakeActivity.open(this, "second", UUID.randomUUID().toString(), "/propertyList");
        });
        button2.setOnClickListener(v -> {
            SnakeFragmentActivity.open(this, "second", UUID.randomUUID().toString(), "/propertyList");
        });
        button3.setOnClickListener(v -> {
            Intent intent1 = new Intent();
            Bundle bundle = new Bundle();
            bundle.putString("name", "This message is from Native!!!");
            intent1.putExtras(bundle);
            setResult(RESULT_OK, intent1);
            finish();
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void finish() {

        super.finish();
    }
}
